package mapper

import (
	"gin-epg/internal/app/dao"
	"gin-epg/internal/app/entity"
)

// CreateEpgProgramCollect 创建一个新的 EpgProgramCollect
func CreateEpgProgramCollect(epgProgramCollect *entity.EpgProgramCollect) (err error) {
	if err = dao.SqlSession.Create(epgProgramCollect).Error; err != nil {
		return err
	}
	return
}

/*
* 获取 EpgProgramCollect 集合
 */
func GetAllEpgProgramCollect() (epgProgramCollectList []*entity.EpgProgramCollect, err error) {
	if err := dao.SqlSession.Find(&epgProgramCollectList).Error; err != nil {
		return nil, err
	}
	return
}

/*
* 根据 id 删除 EpgProgramCollect
 */
func DeleteEpgProgramCollectById(id string) (err error) {
	err = dao.SqlSession.Where("id=?", id).Delete(&entity.EpgProgramCollect{}).Error
	return
}

/*
* 根据 id 查询 EpgProgramCollect
 */
func GetEpgProgramCollectById(id string) (epgProgramCollect *entity.EpgProgramCollect, err error) {
	// 初始化 epgProgramCollect 变量
	epgProgramCollect = new(entity.EpgProgramCollect)

	// 执行查询
	if err = dao.SqlSession.Where("id=?", id).First(epgProgramCollect).Error; err != nil {
		return nil, err
	}
	return epgProgramCollect, nil
}

/*
* 更新 EpgProgramCollect 信息
 */
func UpdateEpgProgramCollect(epgProgramCollect *entity.EpgProgramCollect) (err error) {
	err = dao.SqlSession.Save(epgProgramCollect).Error
	return
}
